package cn.gson.springboot.model.pojos;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Objects;

@Entity
@Table(name = "product_", schema = "crm")
public class Product {
    private int productId;
    private String productCode;
    private Integer productState;
    private Integer productStock;
    private BigDecimal productCost;
    private Integer stockUpperLimit;
    private String productName;
    private String productModel;
    private BigDecimal productPrice;
    private ProductClassify productClassifyByProductClassifyId;
    private Collection<ProductDetail> productDetailsByProductId;
    private Collection<StorageDetail> storageDetailsByProductId;

    @Id
    @Column(name = "product_id", nullable = false)
    public int getProductId() {
        return productId;
    }

    public void setProductId(int productId) {
        this.productId = productId;
    }


    @Basic
    @Column(name = "product_code", nullable = true, length = 255)
    public String getProductCode() {
        return productCode;
    }

    public void setProductCode(String productCode) {
        this.productCode = productCode;
    }

    @Basic
    @Column(name = "product_state", nullable = true)
    public Integer getProductState() {
        return productState;
    }

    public void setProductState(Integer productState) {
        this.productState = productState;
    }

    @Basic
    @Column(name = "product_stock", nullable = true)
    public Integer getProductStock() {
        return productStock;
    }

    public void setProductStock(Integer productStock) {
        this.productStock = productStock;
    }

    @Basic
    @Column(name = "product_cost", nullable = true, precision = 2)
    public BigDecimal getProductCost() {
        return productCost;
    }

    public void setProductCost(BigDecimal productCost) {
        this.productCost = productCost;
    }

    @Basic
    @Column(name = "stock_upper_limit", nullable = true)
    public Integer getStockUpperLimit() {
        return stockUpperLimit;
    }

    public void setStockUpperLimit(Integer stockUpperLimit) {
        this.stockUpperLimit = stockUpperLimit;
    }


    @Basic
    @Column(name = "product_name", nullable = true, length = 255)
    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    @Basic
    @Column(name = "product_model", nullable = true, length = 255)
    public String getProductModel() {
        return productModel;
    }

    public void setProductModel(String productModel) {
        this.productModel = productModel;
    }


    @Basic
    @Column(name = "product_price", nullable = true, precision = 2)
    public BigDecimal getProductPrice() {
        return productPrice;
    }

    public void setProductPrice(BigDecimal productPrice) {
        this.productPrice = productPrice;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Product product = (Product) o;
        return productId == product.productId &&
                Objects.equals(productCode, product.productCode) &&
                Objects.equals(productState, product.productState) &&
                Objects.equals(productStock, product.productStock) &&
                Objects.equals(productCost, product.productCost) &&
                Objects.equals(stockUpperLimit, product.stockUpperLimit) &&
                Objects.equals(productModel, product.productModel) &&
                Objects.equals(productName, product.productName) &&
                Objects.equals(productPrice, product.productPrice);
    }

    @Override
    public int hashCode() {
        return Objects.hash(productId, productCode, productState, productStock, productCost, stockUpperLimit, productModel,productName, productPrice);
    }

    @ManyToOne
    @JoinColumn(name = "product_classify_id", referencedColumnName = "product_classify_id")
    public ProductClassify getProductClassifyByProductClassifyId() {
        return productClassifyByProductClassifyId;
    }

    public void setProductClassifyByProductClassifyId(ProductClassify productClassifyByProductClassifyId) {
        this.productClassifyByProductClassifyId = productClassifyByProductClassifyId;
    }

    @OneToMany(mappedBy = "productByProductId")
    public Collection<ProductDetail> getProductDetailsByProductId() {
        return productDetailsByProductId;
    }

    public void setProductDetailsByProductId(Collection<ProductDetail> productDetailsByProductId) {
        this.productDetailsByProductId = productDetailsByProductId;
    }

    @OneToMany(mappedBy = "productByProductId")
    public Collection<StorageDetail> getStorageDetailsByProductId() {
        return storageDetailsByProductId;
    }

    public void setStorageDetailsByProductId(Collection<StorageDetail> storageDetailsByProductId) {
        this.storageDetailsByProductId = storageDetailsByProductId;
    }
}
